<?php
	require_once("disable_magic_quotes.php");
	require_once("CertFileAccessor.php");
	require_once("OAuth.php");
	
	$payload = array();
    $cert_accessor = new CertFileAccessor(dirname(__FILE__).'/oauth_cert_files', 'orkut');
    $cert = $cert_accessor->getPublicKey($_REQUEST['xoauth_signature_publickey']);
    
    if ($cert != null) {
        
        class KeystoreRSASignatureMethod extends OAuthSignatureMethod_RSA_SHA1 {
            public function __construct($cert) {
              $this->_cert = $cert;
            }
            
            protected function fetch_public_cert(&$request) {
                return $this->_cert;
            }
        }
		
        // cria request
		$request = OAuthRequest::from_request(null, null, array_merge($_GET, $_POST));
		
		// cria assinatura
        $signature_method = new KeystoreRSASignatureMethod($cert);

		// verifica autorizacao
        $authresposta = $signature_method->check_signature($request, null, null, $_GET["oauth_signature"]); 
		
    } else {
       $payload['cert'] = 'missing';
    }

    if ($authresposta == 1) {
        $payload["auth"] = "OK";
    } else {
        $payload["auth"] = "Failed";
    }

?>